package com.azkj.album.presenter;

import com.azkj.album.dto.LoginBean;
import com.azkj.album.network.NetworkMaster;
import com.azkj.album.network.callback.ServiceCallback;
import com.azkj.album.network.networkframe.bean.BaseResp;
import com.azkj.album.network.networkframe.net.exception.ApiException;
import com.azkj.album.view.iview.IBindView;
import com.azkj.album.view.widgets.dialog.DialogHelper;

import java.util.Map;

public class BindPhonePresenter extends SendSmsPresenter {

    private final IBindView iView;


    public BindPhonePresenter(IBindView iView) {
        super(iView);
        this.iView = iView;
    }


    public void bindPhone(Map<String, Object> body) {
        NetworkMaster.getInstance().getCommonService().registerWx(body, new ServiceCallback<BaseResp<LoginBean>>() {
            @Override
            public void onSuccess(BaseResp<LoginBean> jsonObj) {
                DialogHelper.hideDialog();
                if (jsonObj.getCode() == 1) {
                    iView.bindSuccess(jsonObj.getData());
                } else {
                    iView.bindFail(jsonObj.getMsg());
                }
            }

            @Override
            public void onError(ApiException apiException) {
                iView.bindFail(apiException.errorInfo.error);
            }

        });


    }


    public void changePsd(Map<String, Object> body) {

        NetworkMaster.getInstance().getCommonService().changePsd(body, new ServiceCallback<BaseResp<String>>() {
            @Override
            public void onSuccess(BaseResp<String> jsonObj) {
                DialogHelper.hideDialog();
                if (jsonObj.getCode() == 1) {
                    iView.changePsdSuccess();
                } else {
                    iView.changePsdFail(jsonObj.getMsg());
                }
            }

            @Override
            public void onError(ApiException apiException) {
                iView.changePsdFail(apiException.errorInfo.error);
            }

        });


    }


}
